//
//  CommonNoticeView.m
//  youlele
//
//  Created by wujian on 2018/3/21.
//  Copyright © 2018年 zongquankeji. All rights reserved.
//

#import "CommonNoticeView.h"

/**
 基类，不单独做处理
 */
@implementation CommonNoticeView

-(id)initWithFrame:(CGRect)frame{
    
    CGRect initialFrame;
    
    if (CGRectIsEmpty(frame)) {
        
        initialFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        
    } else {
        
        initialFrame = frame;
    }
    
    self = [super initWithFrame:initialFrame];
    
    if (self) {
   
        /**
         背景图
         */
        UIView *alphaView = [[UIView alloc] init];
        alphaView.backgroundColor = [CSBlackColor colorWithAlphaComponent:0.7];
        [self addSubview:alphaView];
        self.alphaView = alphaView;
        
        /**
         白色背景
         */
        UIView *whiteView = [[UIView alloc] init];
        whiteView.backgroundColor = CSWhiteColor;
        whiteView.layer.cornerRadius = 6;
        whiteView.layer.masksToBounds = YES;
        [self addSubview:whiteView];
        self.whiteView = whiteView;
        
        
        /**
         标题
         */
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.font = BigFont;
        titleLabel.textColor = CSColorFromRGB(0x222222);
        [whiteView addSubview:titleLabel];
        self.titleLabel = titleLabel;;
        
        
        /**
         线条
         */
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = LineBackGroundColor;
        [whiteView addSubview:lineView];
        self.lineView = lineView;
        
        /**
         关闭按钮
         */
        UIButton *closeBtn = [[UIButton alloc] init];
        [closeBtn addTarget:self action:@selector(hiddenWithAnimation)];
        [closeBtn setImage:@"pop_icon_close"];
        [whiteView addSubview:closeBtn];
        self.closeBtn = closeBtn;
        
        
        /**
         取消
         */
        UIButton *cancleBtn = [[UIButton alloc] init];
        [cancleBtn setTitle:@"取消"];
        [cancleBtn setTitleColor:CSColorFromRGB(0x666666)];
        cancleBtn.titleLabel.font = MidFont;
//        cancleBtn.layer.borderColor = CSColorFromRGB(0x999999).CGColor;
//        cancleBtn.layer.borderWidth = 1.0;
        cancleBtn.backgroundColor = CSColorFromRGB(0xECE8D9);
        cancleBtn.layer.masksToBounds = YES;
        [cancleBtn addTarget:self action:@selector(hiddenWithAnimation)];
        cancleBtn.layer.cornerRadius = 20;
        [whiteView addSubview:cancleBtn];
        self.cancleBtn = cancleBtn;
        
        
        /**
         确定
         */
        UIButton *sureBtn = [[UIButton alloc] init];
        [sureBtn setTitle:@"确定"];
        [sureBtn setTitleColor:ButtonTextColor];
        //[sureBtn setBgImage:@"btn_yellow"];
        sureBtn.titleLabel.font = MidFont;
//        sureBtn.backgroundColor = ButtonBackGroundColor;
        [sureBtn addTarget:self action:@selector(hiddenWithAnimation)];
        sureBtn.layer.masksToBounds = YES;
        sureBtn.layer.cornerRadius = 20;
        [whiteView addSubview:sureBtn];
        self.sureBtn = sureBtn;
        
        //[self setConstraints];
    }
    
    return self;
}


/**
 设置约束
 */
-(void)setConstraints{
    
    /**
     背景图
     */
    [self.alphaView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self);
    }];
    
    /**
     白色背景
     */
    [self.whiteView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.center.mas_equalTo(self);
        
        make.left.mas_equalTo(self).offset(20);
        
        make.right.mas_equalTo(self).offset(-20);
    }];
    
    /**
     标题
     */
    [self. titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.whiteView).offset(15);
        
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    /**
     线条
     */
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(15);
        
        make.left.width.mas_equalTo(self.whiteView);
        
        make.height.mas_equalTo(1);
    }];
    
    /**
     关闭按钮
     */
    [self.closeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.whiteView).offset(15);
        
        make.right.mas_equalTo(self.whiteView).offset(-15);
    }];
    
}

- (void)addViews {
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    [window addSubview:self];
}

- (void)hiddenViews {
    
    [self removeFromSuperview];
}


/**
 显示页面
 */
- (void)showWithAnimation{
    
    [self addViews];
    
    self.whiteView.transform = CGAffineTransformScale(CGAffineTransformIdentity, CGFLOAT_MIN, CGFLOAT_MIN);
    
    [UIView animateWithDuration:0.3 animations:^{
        
        self.whiteView.transform = CGAffineTransformIdentity;
        
    }];
}


/**
 隐藏页面
 */
- (void)hiddenWithAnimation {
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.whiteView.transform = CGAffineTransformScale( CGAffineTransformIdentity, 0.001, 0.001);
        
    } completion:^(BOOL finished) {
        
        [self hiddenViews];
    }];
}

-(void)layoutSubviews{
    
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = self.sureBtn.bounds;  // 设置显示的frame
    gradientLayer.colors = @[(id)CSColorFromRGB(0xFFEC00).CGColor,(id)CSColorFromRGB(0xFECD00).CGColor];  // 设置渐变颜色
    gradientLayer.startPoint = CGPointMake(0, 0);   //
    gradientLayer.endPoint = CGPointMake(1, 0);     //
    [self.sureBtn.layer insertSublayer:gradientLayer atIndex:0];
}

@end









/**
 没有图片，只有一个标题Label
 */
@implementation CommonNoticeView1


-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        /**
         提示标题
         */
        UILabel *noticeTitleLabel = [[UILabel alloc] init];
        noticeTitleLabel.font = BigFont;
        noticeTitleLabel.textColor = CSColorFromRGB(0x222222);
        [self.whiteView addSubview:noticeTitleLabel];
        self.noticeTitleLabel = noticeTitleLabel;
        
        [self setConstraints];
        
    }
    
    return self;
}


/**
 设置约束
 */
-(void)setConstraints{
    
    [super setConstraints];
    
    
    /**
     提示标题
     */
    [self.noticeTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(20);
        
        make.centerX.mas_equalTo(self);
    }];
    
    
    /**
     取消
     */
    [self.cancleBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeTitleLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.right.mas_equalTo(self.whiteView.mas_centerX).offset(-15);
        
        make.height.mas_equalTo(40);
        
        make.width.mas_equalTo(self.whiteView).multipliedBy(1.5/4);
    }];
    
    
    /**
     确定
     */
    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeTitleLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.left.mas_equalTo(self.whiteView.mas_centerX).offset(15);
        
        make.width.height.mas_equalTo(self.cancleBtn);
        
    }];
    
    
}
@end







/**
 没有图片，有一个标题Label，还有一个详情Label
 */
@implementation CommonNoticeView2

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame ];
    
    if (self) {
        
        /**
         提示标题
         */
        UILabel *noticeTitleLabel = [[UILabel alloc] init];
        noticeTitleLabel.font = BigFont;
        noticeTitleLabel.textColor = CSColorFromRGB(0x222222);
        noticeTitleLabel.numberOfLines = 0;
        [self.whiteView addSubview:noticeTitleLabel];
        self.noticeTitleLabel = noticeTitleLabel;
        
        /**
         提示详情
         */
        UILabel *noticeDetailLabel = [[UILabel alloc] init];
        noticeDetailLabel.font = MidFont;
        noticeDetailLabel.textColor = CSColorFromRGB(0x666666);
        noticeDetailLabel.numberOfLines = 0;
        [self.whiteView addSubview:noticeDetailLabel];
        self.noticeDetailLabel = noticeDetailLabel;;
        
        [self setConstraints];
    }
    
    return self;
}


/**
 设置约束
 */
-(void)setConstraints{
    
    [super setConstraints];
    
    
    /**
     提示标题
     */
    [self.noticeTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(20);
        
        make.centerX.mas_equalTo(self);
    }];
    
    
    /**
     提示详情
     */
    [self.noticeDetailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.noticeTitleLabel.mas_bottom).offset(12);
        
        make.centerX.mas_equalTo(self);
    }];
    
    /**
     取消
     */
    [self.cancleBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeDetailLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.right.mas_equalTo(self.whiteView.mas_centerX).offset(-15);
        
        make.height.mas_equalTo(40);
        
        make.width.mas_equalTo(self.whiteView).multipliedBy(1.5/4);
    }];
    
    
    /**
     确定
     */
    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeDetailLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.left.mas_equalTo(self.whiteView.mas_centerX).offset(15);
        
        make.width.height.mas_equalTo(self.cancleBtn);
    }];
    
    
}

@end


/**
 有图片，有一个标题Label
 */
@implementation CommonNoticeView3

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        /**
         提示图片
         */
        UIImageView *noticeImageView = [[UIImageView alloc] init];
        [self.whiteView addSubview:noticeImageView];
        self.noticeImageView = noticeImageView;
        
        
        /**
         提示标题
         */
        TTTAttributedLabel *noticeTitleLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        noticeTitleLabel.delegate = self;
        noticeTitleLabel.font = SmallFont;
        noticeTitleLabel.textColor = CSColorFromRGB(0x222222);
        noticeTitleLabel.numberOfLines = 0;
        noticeTitleLabel.lineBreakMode = NSLineBreakByCharWrapping;
        noticeTitleLabel.textAlignment = NSTextAlignmentCenter;
        //检测url
        noticeTitleLabel.enabledTextCheckingTypes=NSTextCheckingTypeLink;
        noticeTitleLabel.linkAttributes = @{(id)kCTForegroundColorAttributeName:CSColorFromRGB(0x157EFB),NSUnderlineStyleAttributeName:@(0)}; //链接高亮状态文本属性
        noticeTitleLabel.activeLinkAttributes = @{(id)kCTForegroundColorAttributeName:CSColorFromRGB(0x157EFB),NSUnderlineStyleAttributeName:@(0)};
        [self.whiteView addSubview:noticeTitleLabel];
        self.noticeTitleLabel = noticeTitleLabel;
        
        self.lineView.hidden = YES;
        
        [self.cancleBtn setTitle:@"暂不绑定"];
        [self.sureBtn setTitle:@"去绑定"];
        [self.sureBtn addTarget:self action:@selector(sureBtnClick)];
        [self setConstraints];
    }
    
    return self;
}


/**
 设置约束
 */
-(void)setConstraints{
    
    [super setConstraints];
    
    
    
    /**
     白色背景
     */
    [self.whiteView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.center.mas_equalTo(self);
        
        make.left.mas_equalTo(self).offset(40);
        
        make.right.mas_equalTo(self).offset(-40);
    }];
    
    /**
     提示图片
     */
    [self.noticeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.whiteView).offset(15);
        
        make.centerX.mas_equalTo(self.whiteView);                
    }];
    
    
    
    /**
     提示标题
     */
    [self.noticeTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeImageView.mas_bottom).offset(20);
        
        make.centerX.mas_equalTo(self);
        
        make.width.mas_equalTo(self.whiteView).multipliedBy(0.6);
    }];
    
    
    /**
     取消
     */
    [self.cancleBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeTitleLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.right.mas_equalTo(self.whiteView.mas_centerX).offset(-15);
        
        make.height.mas_equalTo(40);
        
        make.width.mas_equalTo(self.whiteView).multipliedBy(1.5/4);
    }];
    
    
    /**
     确定
     */
    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeTitleLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.left.mas_equalTo(self.whiteView.mas_centerX).offset(15);
        
        make.height.width.mas_equalTo(self.cancleBtn);
    }];
    
}


-(void)setNoticeText:(NSString *)noticeText{
    
    NSString *text = noticeText;
    [self.noticeTitleLabel setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
        
        //设置可点击文字的范围
        NSRange boldRange = [text rangeOfString:@"《互联网跟帖服务管理规定》" options:NSCaseInsensitiveSearch];
        
        //设置可点击文本的颜色
        [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[CSColorFromRGB(0x157EFB) CGColor] range:boldRange];
        return mutableAttributedString;
    }];
    
    //设置可点击文字的范围
    NSRange boldRange = [text rangeOfString:@"《互联网跟帖服务管理规定》" options:NSCaseInsensitiveSearch];
    
    //设置链接的url
    [self.noticeTitleLabel addLinkToURL:[NSURL URLWithString:@""] withRange:boldRange];
}


/**
 TTTAttributedLabel Delegate
 */
- (void)attributedLabel:(TTTAttributedLabel*)label didSelectLinkWithURL:(NSURL*)url{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self hiddenWithAnimation];
        
        
    });
    
    
}

-(void)sureBtnClick
{
    
    [self hiddenWithAnimation];
    
    if (self.sureBlock) {
        self.sureBlock();
    }
}

- (void)addViews {
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    [window addSubview:self];
}

- (void)hiddenViews {
    
    [self removeFromSuperview];
}


/**
 显示页面
 */
- (void)showWithAnimation{
    
    [self addViews];
    
    self.whiteView.transform = CGAffineTransformScale(CGAffineTransformIdentity, CGFLOAT_MIN, CGFLOAT_MIN);
    
    [UIView animateWithDuration:0.3 animations:^{
        
        self.whiteView.transform = CGAffineTransformIdentity;
        
    }];
}


/**
 隐藏页面
 */
- (void)hiddenWithAnimation {
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.whiteView.transform = CGAffineTransformScale( CGAffineTransformIdentity, 0.001, 0.001);
        
    } completion:^(BOOL finished) {
        
        [self hiddenViews];
    }];
}

@end






/**
 有图片，有一个标题Label，还有一个详情
 */

@implementation CommonNoticeView4

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        /**
         提示图片
         */
        UIImageView *noticeImageView = [[UIImageView alloc] init];
        noticeImageView.backgroundColor = CSRedColor;
        [self.whiteView addSubview:noticeImageView];
        self.noticeImageView = noticeImageView;
        
        /**
         提示标题
         */
        UILabel *noticeTitleLabel = [[UILabel alloc] init];
        noticeTitleLabel.font = BigFont;
        noticeTitleLabel.textColor = CSColorFromRGB(0x222222);
        noticeTitleLabel.numberOfLines = 0;
        [self.whiteView addSubview:noticeTitleLabel];
        self.noticeTitleLabel = noticeTitleLabel;
        
        /**
         提示详情
         */
        UILabel *noticeDetailLabel = [[UILabel alloc] init];
        noticeDetailLabel.font = MidFont;
        noticeDetailLabel.textColor = CSColorFromRGB(0x666666);
        noticeDetailLabel.numberOfLines = 0;
        [self.whiteView addSubview:noticeDetailLabel];
        self.noticeDetailLabel = noticeDetailLabel;;
        
        [self setConstraints];
    }
    
    return self;
}

/**
 设置约束
 */
-(void)setConstraints{
    
    [super setConstraints];
    
    /**
     提示图片
     */
    [self.noticeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(20);
        
        make.centerX.mas_equalTo(self.whiteView);
        
        make.width.height.mas_equalTo(60);
    }];
    
    
    
    /**
     提示标题
     */
    [self.noticeTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeImageView.mas_bottom).offset(20);
        
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    /**
     提示详情
     */
    [self.noticeDetailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeTitleLabel.mas_bottom).offset(12);
        
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    
    /**
     取消
     */
    [self.cancleBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeDetailLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.right.mas_equalTo(self.whiteView.mas_centerX).offset(-15);
        
        make.height.mas_equalTo(40);
        
        make.width.mas_equalTo(self.whiteView).multipliedBy(1.5/4);
    }];
    
    
    /**
     确定
     */
    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeTitleLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.left.mas_equalTo(self.whiteView.mas_centerX).offset(15);
        
        make.width.height.mas_equalTo(self.cancleBtn);
        
    }];
    
}

@end





/**
 有图片，多个详情
 */
@interface CommonNoticeView5()

@property(nonatomic,strong)NSMutableArray *titleLabelArray;

@end


@implementation CommonNoticeView5

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.titleLabelArray = [[NSMutableArray alloc] init];
        
        /**
         提示图片
         */
        UIImageView *noticeImageView = [[UIImageView alloc] init];
        [self.whiteView addSubview:noticeImageView];
        self.noticeImageView = noticeImageView;
        
        //[self setConstraints];
        
    }
    
    return self;
}


-(void)setConstraints{
    
    [super setConstraints];
    
    self.cancleBtn.hidden = YES;
    
    /**
     提示图片
     */
    [self.noticeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(20);
        
        make.centerX.mas_equalTo(self.whiteView);
        
        //make.width.height.mas_equalTo(60);
    }];
    
    UILabel *tmpLabel;
    
    for (UILabel *label in self.titleLabelArray) {
        
        [label mas_remakeConstraints:^(MASConstraintMaker *make) {
           
            if (tmpLabel) {
                
                make.top.mas_equalTo(tmpLabel.mas_bottom).offset(20);
                
            }else{
                
                make.top.mas_equalTo(self.noticeImageView.mas_bottom).offset(20);
            }
            
            make.left.mas_equalTo(self.whiteView).offset(15);
            
            make.right.mas_equalTo(self.whiteView).offset(-15);
        }];
        
        tmpLabel = label;
    }
    
    /**
     取消
     */
    [self.cancleBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(tmpLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.right.mas_equalTo(self.whiteView.mas_centerX).offset(-15);
        
        make.height.mas_equalTo(40);
        
        make.width.mas_equalTo(self.whiteView).multipliedBy(1.5/4);
    }];
    
    
    /**
     确定
     */
    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(tmpLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.centerX.mas_equalTo(self.whiteView);
        
        make.width.height.mas_equalTo(self.cancleBtn);
    }];
}


/**
 设置标题
 */
-(void)setTitleArray:(NSMutableArray *)titleArray{
    
    _titleArray = titleArray;
    
    for (NSString *title in titleArray) {
        
        UILabel *noticeDetailLabel = [[UILabel alloc] init];
        noticeDetailLabel.font = MidFont;
        noticeDetailLabel.textColor = CSColorFromRGB(0x666666);
        noticeDetailLabel.numberOfLines = 0;
        noticeDetailLabel.lineBreakMode = NSLineBreakByCharWrapping;
        NSString *str = [NSString stringWithFormat:@"• %@",title];
        noticeDetailLabel.attributedText = [self strWithRed:str];
        [self.whiteView addSubview:noticeDetailLabel];
        [self.titleLabelArray addObject:noticeDetailLabel];
    }
    
    [self setConstraints];
}


-(NSMutableAttributedString *)strWithRed:(NSString *)str{
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:str];
    
    [attStr addAttribute:NSForegroundColorAttributeName value:ButtonBackGroundColor range:[str rangeOfString:@"•"]];
    
    [attStr addAttribute:NSFontAttributeName value:BigBigFont range:[str rangeOfString:@"•"]];
    
    return attStr;
}

@end

/**
 有图片，有一个标题Label，还有一个详情
 */

@implementation CommonNoticeView6


-(id)initWithFrame:(CGRect)frame{
    
    CGRect initialFrame;
    
    if (CGRectIsEmpty(frame)) {
        
        initialFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        
    } else {
        
        initialFrame = frame;
    }
    
    self = [super initWithFrame:initialFrame];
    
    if (self) {
        
        /**
         背景图
         */
        UIView *alphaView = [[UIView alloc] init];
        alphaView.backgroundColor = [CSBlackColor colorWithAlphaComponent:0.7];
        [self addSubview:alphaView];
        self.alphaView = alphaView;
        
        /**
         白色背景
         */
        UIView *whiteView = [[UIView alloc] init];
        whiteView.backgroundColor = CSWhiteColor;
        whiteView.layer.cornerRadius = 6;
        whiteView.layer.masksToBounds = YES;
        [self addSubview:whiteView];
        self.whiteView = whiteView;
        
        
        /**
         标题
         */
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.font = BigFont;
        titleLabel.textColor = CSColorFromRGB(0x222222);
        [whiteView addSubview:titleLabel];
        self.titleLabel = titleLabel;;
        
        
        /**
         线条
         */
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = LineBackGroundColor;
        [whiteView addSubview:lineView];
        self.lineView = lineView;
        
        /**
         关闭按钮
         */
        UIButton *closeBtn = [[UIButton alloc] init];
        [closeBtn addTarget:self action:@selector(hiddenWithAnimation)];
        [closeBtn setImage:@"pop_icon_close"];
        closeBtn.contentEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
        [whiteView addSubview:closeBtn];
        self.closeBtn = closeBtn;
        
        
        /**
         取消
         */
        UIButton *cancleBtn = [[UIButton alloc] init];
        [cancleBtn setTitle:@"取消"];
        [cancleBtn setTitleColor:CSColorFromRGB(0x666666)];
        cancleBtn.titleLabel.font = MidFont;
        //        cancleBtn.layer.borderColor = CSColorFromRGB(0x999999).CGColor;
        //        cancleBtn.layer.borderWidth = 1.0;
        cancleBtn.backgroundColor = CSColorFromRGB(0xECE8D9);
        cancleBtn.layer.masksToBounds = YES;
        [cancleBtn addTarget:self action:@selector(hiddenWithAnimation)];
        cancleBtn.layer.cornerRadius = 20;
        [whiteView addSubview:cancleBtn];
        self.cancleBtn = cancleBtn;
        
        
        /**
         确定
         */
        UIButton *sureBtn = [[UIButton alloc] init];
        [sureBtn setTitle:@"去打开"];
        [sureBtn setTitleColor:ButtonTextColor];
        [sureBtn setBgImage:@"btn_yellow"];
        sureBtn.titleLabel.font = MidFont;
        //        sureBtn.backgroundColor = ButtonBackGroundColor;
        [sureBtn addTarget:self action:@selector(sure:)];
        sureBtn.layer.masksToBounds = YES;
        sureBtn.layer.cornerRadius = 20;
        [whiteView addSubview:sureBtn];
        self.sureBtn = sureBtn;
        
        /**
         提示图片
         */
        UIImageView *noticeImageView = [[UIImageView alloc] init];
        noticeImageView.image = PlaceHold;
        [self.whiteView addSubview:noticeImageView];
        self.noticeImageView = noticeImageView;
        
        /**
         提示标题
         */
        UILabel *noticeTitleLabel = [[UILabel alloc] init];
        noticeTitleLabel.font = kFont16;
        noticeTitleLabel.textColor = CSColorFromRGB(0x222222);
        noticeTitleLabel.numberOfLines = 0;
        [self.whiteView addSubview:noticeTitleLabel];
        self.noticeTitleLabel = noticeTitleLabel;
        
        /**
         提示详情
         */
        UILabel *noticeDetailLabel = [[UILabel alloc] init];
        noticeDetailLabel.font = MidFont;
        noticeDetailLabel.textColor = CSColorFromRGB(0x999999);
        noticeDetailLabel.numberOfLines = 0;
        [self.whiteView addSubview:noticeDetailLabel];
        self.noticeDetailLabel = noticeDetailLabel;;
        
        [self setConstraints];
        
        
        
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
      背景图
      */
     [self.alphaView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self);
    }];
     
     /**
      白色背景
      */
     [self.whiteView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.center.mas_equalTo(self);
        
        make.width.mas_equalTo(SCREENWIDTH/4*3);
    }];
     
     
     
     /**
      关闭按钮
      */
     [self.closeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.whiteView).offset(10);
        
        make.right.mas_equalTo(self.whiteView).offset(-10);
    }];
    
    
    
    /**
     提示图片
     */
    [self.noticeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.whiteView).offset(20);
        
        make.centerX.mas_equalTo(self.whiteView);
        
    }];
    
    
    
    /**
     提示标题
     */
    [self.noticeTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeImageView.mas_bottom).offset(20);
        make.left.mas_greaterThanOrEqualTo(self.whiteView).offset(20);
        make.right.mas_lessThanOrEqualTo(self.whiteView).offset(-20);
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    /**
     提示详情
     */
    [self.noticeDetailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeTitleLabel.mas_bottom).offset(15);
        make.left.mas_greaterThanOrEqualTo(self.whiteView).offset(20);
        make.right.mas_lessThanOrEqualTo(self.whiteView).offset(-20);
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    
    /**
     取消
     */
    [self.cancleBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeDetailLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.right.mas_equalTo(self.whiteView.mas_centerX).offset(-15);
        
        make.height.mas_equalTo(40);
        
        make.width.mas_equalTo(self.whiteView).multipliedBy(1.5/4);
    }];
    
    
    /**
     确定
     */
    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.cancleBtn);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        
        make.left.mas_equalTo(self.whiteView.mas_centerX).offset(15);
        
        make.width.height.mas_equalTo(self.cancleBtn);
        
    }];
    
//    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(self.whiteView).offset(20);
//        make.right.mas_equalTo(self.whiteView).offset(-20);
//        make.top.mas_equalTo(self.titleBtn.mas_bottom).offset(20);
//        make.height.mas_equalTo(40);
//        make.bottom.mas_equalTo(self.whiteView).offset(-20);
//    }];
    
}



-(void)sure:(UIButton *)sender
{
    
    [self hiddenWithAnimation];
    
    if (self.sureBlock) {
        self.sureBlock();
    }
}




- (void)showWithAnimation {
    [self addViews];
    self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
    CGFloat height = self.whiteView.frame.size.height;
    self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT + height / 2);
    [UIView animateWithDuration:0.25 animations:^{
        self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT - height / 2);
        self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
    }];
    
}

- (void)hiddenWithAnimation {
    CGFloat height = self.whiteView.frame.size.height;
    [UIView animateWithDuration:0.25 animations:^{
        self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT + height / 2);
        self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
    } completion:^(BOOL finished) {
        [self hiddenViews];
    }];
}

- (void)addViews {
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    [window addSubview:self];
}

- (void)hiddenViews {
    
    [self removeFromSuperview];
}



@end
/**
 有图片，有一个标题Label，单个按钮确定
 */

@implementation CommonNoticeView7


-(id)initWithFrame:(CGRect)frame{
    
    CGRect initialFrame;
    
    if (CGRectIsEmpty(frame)) {
        
        initialFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        
    } else {
        
        initialFrame = frame;
    }
    
    self = [super initWithFrame:initialFrame];
    
    if (self) {
        
        /**
         背景图
         */
        UIView *alphaView = [[UIView alloc] init];
        alphaView.backgroundColor = [CSBlackColor colorWithAlphaComponent:0.7];
        [self addSubview:alphaView];
        self.alphaView = alphaView;
        
        /**
         白色背景
         */
        UIView *whiteView = [[UIView alloc] init];
        whiteView.backgroundColor = CSWhiteColor;
        whiteView.layer.cornerRadius = 6;
        whiteView.layer.masksToBounds = YES;
        [self addSubview:whiteView];
        self.whiteView = whiteView;
        
        
        /**
         标题
         */
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.font = BigFont;
        titleLabel.textColor = CSColorFromRGB(0x222222);
        [whiteView addSubview:titleLabel];
        self.titleLabel = titleLabel;;
        
        
        /**
         线条
         */
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = LineBackGroundColor;
        [whiteView addSubview:lineView];
        self.lineView = lineView;
        
        /**
         提示图片
         */
        UIImageView *noticeImageView = [[UIImageView alloc] init];
        noticeImageView.image = PlaceHold;
        [self.whiteView addSubview:noticeImageView];
        self.noticeImageView = noticeImageView;
        
        
        /**
         关闭按钮
         */
        UIButton *closeBtn = [[UIButton alloc] init];
        [closeBtn addTarget:self action:@selector(hiddenWithAnimation)];
        [closeBtn setImage:@"pop_icon_close"];
        closeBtn.contentEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
        [whiteView addSubview:closeBtn];
        self.closeBtn = closeBtn;
        
        
        /**
         取消
         */
        UIButton *cancleBtn = [[UIButton alloc] init];
        [cancleBtn setTitle:@"取消"];
        [cancleBtn setTitleColor:CSColorFromRGB(0x666666)];
        cancleBtn.titleLabel.font = MidFont;
        //        cancleBtn.layer.borderColor = CSColorFromRGB(0x999999).CGColor;
        //        cancleBtn.layer.borderWidth = 1.0;
        cancleBtn.backgroundColor = CSColorFromRGB(0xECE8D9);
        cancleBtn.layer.masksToBounds = YES;
        [cancleBtn addTarget:self action:@selector(hiddenWithAnimation)];
        cancleBtn.layer.cornerRadius = 20;
        [whiteView addSubview:cancleBtn];
        self.cancleBtn = cancleBtn;
        
        
        /**
         确定
         */
        UIButton *sureBtn = [[UIButton alloc] init];
        [sureBtn setTitle:@"确定"];
        [sureBtn setTitleColor:ButtonTextColor];
        [sureBtn setBgImage:@"btn-2"];
        sureBtn.titleLabel.font = MidFont;
        //        sureBtn.backgroundColor = ButtonBackGroundColor;
        [sureBtn addTarget:self action:@selector(sure:)];
        
        [whiteView addSubview:sureBtn];
        self.sureBtn = sureBtn;
        
        
        
        /**
         提示标题
         */
        UILabel *noticeTitleLabel = [[UILabel alloc] init];
        noticeTitleLabel.font = kFont16;
        noticeTitleLabel.textColor = CSColorFromRGB(0x222222);
        noticeTitleLabel.numberOfLines = 0;
        [self.whiteView addSubview:noticeTitleLabel];
        self.noticeTitleLabel = noticeTitleLabel;
        
        /**
         提示详情
         */
        UILabel *noticeDetailLabel = [[UILabel alloc] init];
        noticeDetailLabel.font = MidFont;
        noticeDetailLabel.textColor = CSColorFromRGB(0x999999);
        noticeDetailLabel.numberOfLines = 0;
        noticeDetailLabel.textAlignment = NSTextAlignmentCenter;
        [self.whiteView addSubview:noticeDetailLabel];
        self.noticeDetailLabel = noticeDetailLabel;;
        
        [self setConstraints];
        
        
        
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
     背景图
     */
    [self.alphaView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self);
    }];
    
    /**
     白色背景
     */
    [self.whiteView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.center.mas_equalTo(self);
        
        make.width.mas_equalTo(SCREENWIDTH/4*3);
    }];
    
    
    
    /**
     关闭按钮
     */
    [self.closeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.whiteView).offset(10);
        
        make.right.mas_equalTo(self.whiteView).offset(-10);
    }];
    
    
    
    /**
     提示图片
     */
    [self.noticeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.whiteView).offset(20);
        
        make.centerX.mas_equalTo(self.whiteView);
        
    }];
    
    
    
    /**
     提示标题
     */
    [self.noticeTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeImageView.mas_bottom).offset(20);
        
        make.centerX.mas_equalTo(self.whiteView);
        
        make.left.mas_greaterThanOrEqualTo(self.whiteView).offset(20);
        make.right.mas_lessThanOrEqualTo(self.whiteView).offset(-20);
    }];
    
    
    /**
     提示副标题
     */
    [self.noticeDetailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeTitleLabel.mas_bottom).offset(10);
        
        make.centerX.mas_equalTo(self.whiteView);
        make.left.mas_greaterThanOrEqualTo(self.whiteView).offset(20);
        make.right.mas_lessThanOrEqualTo(self.whiteView).offset(-20);
    }];
    
    
    
    
    
    /**
     确定
     */
    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeDetailLabel.mas_bottom).offset(20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-15);
        make.left.mas_greaterThanOrEqualTo(20);
        make.right.mas_lessThanOrEqualTo(-20);
        make.centerX.mas_equalTo(self.whiteView);
        
    }];
    
    //    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
    //        make.left.mas_equalTo(self.whiteView).offset(20);
    //        make.right.mas_equalTo(self.whiteView).offset(-20);
    //        make.top.mas_equalTo(self.titleBtn.mas_bottom).offset(20);
    //        make.height.mas_equalTo(40);
    //        make.bottom.mas_equalTo(self.whiteView).offset(-20);
    //    }];
    
}



-(void)sure:(UIButton *)sender
{

    [self hiddenWithAnimation];

    if (self.sureBlock) {
        self.sureBlock();
    }
}




- (void)showWithAnimation {
    [self addViews];
    self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
    CGFloat height = self.whiteView.frame.size.height;
    self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT + height / 2);
    [UIView animateWithDuration:0.25 animations:^{
        self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT - height / 2);
        self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
    }];
    
}

- (void)hiddenWithAnimation {
    CGFloat height = self.whiteView.frame.size.height;
    [UIView animateWithDuration:0.25 animations:^{
        self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT + height / 2);
        self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
    } completion:^(BOOL finished) {
        [self hiddenViews];
    }];
}

- (void)addViews {
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    [window addSubview:self];
}

- (void)hiddenViews {
    
    [self removeFromSuperview];
}



@end

